package com.example.todolist.controller;


import com.example.todolist.common.CheckLogin;
import com.example.todolist.dto.sys.EditUserInfoDTO;
import com.example.todolist.dto.sys.WxAuthLoginOrRegisterDTO;
import com.example.todolist.response.BaseResponse;
import com.example.todolist.response.SystemResponse;
import com.example.todolist.service.SysUserService;
import com.example.todolist.service.impl.WxServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 系统用户表 前端控制器
 * </p>
 *
 * @author admin
 * @since 2022-02-24
 */
@CrossOrigin
@RestController
@RequestMapping("/sys")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@Api(tags = "用户模块", value = "用户controller")
public class SysUserController {

    private final SysUserService sysUserService;

    private final WxServiceImpl wxService;

    @ApiOperation("获取用户")
    @GetMapping("/list")
    public BaseResponse list(){
        return SystemResponse.success(sysUserService.list());
    }

    @GetMapping("/getWxOpenId")
    public BaseResponse getWxOpenId(String code){
        return wxService.getWxOpenId(code);
    }

    @PostMapping("/wxAuthLoginOrRegister")
    public BaseResponse wxAuthLoginOrRegister(@Validated @RequestBody WxAuthLoginOrRegisterDTO wxAuthLoginOrRegisterDTO){
        return wxService.wxAuthLoginOrRegister(wxAuthLoginOrRegisterDTO);
    }

    @CheckLogin
    @GetMapping("/getUserInfo")
    public BaseResponse getUserInfo(){
        return sysUserService.getUserInfo();
    }

    @CheckLogin
    @PostMapping("/editUserInfo")
    public BaseResponse editUserInfo(@Validated @RequestBody EditUserInfoDTO editUserInfoDTO){
        return sysUserService.editUserInfo(editUserInfoDTO);
    }


}

